﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Qplus.enums;
using System.Collections.Generic;

namespace Qplus.protocol
{
    public class MessageID : IMessageID
    {
        /**
	    * 协议对应的包
	    */
        private TCPPackage body;
        private static Dictionary<int, MessageID> map;

        private static MessageID instance;

        public TCPPackage getBody()
        {
            if (this.body == null)
            {
                return null;
            }
            return this.body;

        }

        
	    public IMessageID getMessageIDEnum(int id) {
		    return getMessageID(id);
	    }


        /**
	     * 通过消息id获取对应的协议
	     * 
	     * @param id
	     * @return
	     */
        public static MessageID getMessageID(int id)
        {
           return map[id];
        }

        public static MessageID getInstance()
        {
            if (instance == null)
            {
                instance = new MessageID();
            }
            return instance;
        }

        public void setBody(MMessageID a)
        {
            MMessageID mID;
            switch (a)
            {
                #region LOG 3000
                case MMessageID.C2L_REQ_LOGIN: this.body = new C2L_REQ_LOGIN(); this.body.setMsgID((int)MMessageID.C2L_REQ_LOGIN);  break;
                case MMessageID.L2C_RESP_LOGIN: this.body = new L2C_RESP_LOGIN(); this.body.setMsgID((int)MMessageID.L2C_RESP_LOGIN); this.body.setReplyID((int)MMessageID.C2L_REQ_LOGIN); break;
                case MMessageID.C2U_REQ_LOGIN: this.body = new C2U_REQ_LOGIN(); this.body.setMsgID((int)MMessageID.C2U_REQ_LOGIN); break;
                case MMessageID.U2C_RESP_LOGIN: this.body = new U2C_RESP_LOGIN(); this.body.setMsgID((int)MMessageID.C2U_REQ_LOGIN); break;
                case MMessageID.C2U_REQ_LOGOUT: this.body = new C2U_REQ_LOGOUT(); this.body.setMsgID((int)MMessageID.C2U_REQ_LOGOUT); break;
                case MMessageID.U2C_RESP_LOGOUT: this.body = new U2C_RESP_LOGOUT(); this.body.setMsgID((int)MMessageID.U2C_RESP_LOGOUT); break;
                case MMessageID.C2U_NOTIFY_CLIENT_ONLINE: this.body = new C2U_NOTIFY_CLIENT_ONLINE(); this.body.setMsgID((int)MMessageID.C2U_NOTIFY_CLIENT_ONLINE); break;
                #endregion
                #region SYS MSG 3100
                case MMessageID.U2C_NOTIFY_SYSTEM_MSG: this.body = new U2C_NOTIFY_SYSTEM_MSG(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_SYSTEM_MSG); break;
                case MMessageID.U2C_SYN_FORCE_LOGOUT: this.body = new U2C_SYN_FORCE_LOGOUT(); this.body.setMsgID((int)MMessageID.U2C_SYN_FORCE_LOGOUT); break;
                //case MMessageID.C2U_REQ_SHORT_MSG: this.body = new C2U_REQ_SHORT_MSG(); this.body.setMsgID((int)MMessageID.C2U_REQ_SHORT_MSG); break;
                //case MMessageID.U2C_RESP_SHORT_MSG: this.body = new U2C_RESP_SHORT_MSG(); this.body.setMsgID((int)MMessageID.U2C_RESP_SHORT_MSG); break;
                //case MMessageID.U2C_NOTIFY_SHORT_MSG: this.body = new U2C_NOTIFY_SHORT_MSG(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_SHORT_MSG); break;
                #endregion
                #region CUSTOM SERVICE 3200
                case MMessageID.C2U_REQ_CUSTOMER_SERVICE: this.body = new C2U_REQ_CUSTOMER_SERVICE(); this.body.setMsgID((int)MMessageID.C2U_REQ_CUSTOMER_SERVICE); break;
                case MMessageID.U2C_RESP_CUSTOMER_SERVICE: this.body = new U2C_RESP_CUSTOMER_SERVICE(); this.body.setMsgID((int)MMessageID.U2C_RESP_CUSTOMER_SERVICE); break;
                case MMessageID.C2U_REQ_SESSION_BEGIN: this.body = new C2U_REQ_SESSION_BEGIN(); this.body.setMsgID((int)MMessageID.C2U_REQ_SESSION_BEGIN); break;
                case MMessageID.U2C_RESP_SESSION_BEGIN: this.body = new U2C_RESP_SESSION_BEGIN(); this.body.setMsgID((int)MMessageID.U2C_RESP_SESSION_BEGIN); break;
                case MMessageID.U2C_NOTIFY_SESSION_BEGIN: this.body = new U2C_NOTIFY_SESSION_BEGIN(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_SESSION_BEGIN); break;
                case MMessageID.C2U_REQ_SESSION_END: this.body = new C2U_REQ_SESSION_END(); this.body.setMsgID((int)MMessageID.C2U_REQ_SESSION_END); break;
                case MMessageID.U2C_RESP_SESSION_END: this.body = new U2C_RESP_SESSION_END(); this.body.setMsgID((int)MMessageID.U2C_RESP_SESSION_END); break;
                case MMessageID.U2C_NOTIFY_SESSION_END: this.body = new U2C_NOTIFY_SESSION_END(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_SESSION_END); break;
                case MMessageID.C2U_REQ_CHAT_SENDMSG: this.body = new C2U_REQ_CHAT_SENDMSG(); this.body.setMsgID((int)MMessageID.C2U_REQ_CHAT_SENDMSG); break;
                case MMessageID.U2C_RESP_CHAT_SENDMSG: this.body = new U2C_RESP_CHAT_SENDMSG(); this.body.setMsgID((int)MMessageID.U2C_RESP_CHAT_SENDMSG); break;
                case MMessageID.U2C_NOTIFY_CHAT_RECVMSG: this.body = new U2C_NOTIFY_CHAT_RECVMSG(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_CHAT_RECVMSG); break;
                case MMessageID.C2U_REQ_CHAT_VOICEBEGIN: this.body = new C2U_REQ_CHAT_VOICEBEGIN(); this.body.setMsgID((int)MMessageID.C2U_REQ_CHAT_VOICEBEGIN); break;
                case MMessageID.U2C_RESP_CHAT_VOICEBEGIN: this.body = new U2C_RESP_CHAT_VOICEBEGIN(); this.body.setMsgID((int)MMessageID.U2C_RESP_CHAT_VOICEBEGIN); break;
                case MMessageID.U2C_NOTIFY_CHAT_VOICEBEGIN: this.body = new U2C_NOTIFY_CHAT_VOICEBEGIN(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_CHAT_VOICEBEGIN); break;
                case MMessageID.C2U_REQ_CHAT_VOICEDATA: this.body = new C2U_REQ_CHAT_VOICEDATA(); this.body.setMsgID((int)MMessageID.C2U_REQ_CHAT_VOICEDATA); break;
                case MMessageID.U2C_NOTIFY_CHAT_VOICEDATA: this.body = new U2C_NOTIFY_CHAT_VOICEDATA(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_CHAT_VOICEDATA); break;
                case MMessageID.C2U_REQ_CHAT_VOICEEND: this.body = new C2U_REQ_CHAT_VOICEEND(); this.body.setMsgID((int)MMessageID.C2U_REQ_CHAT_VOICEEND); break;
                case MMessageID.U2C_RESP_CHAT_VOICEEND: this.body = new U2C_RESP_CHAT_VOICEEND(); this.body.setMsgID((int)MMessageID.U2C_RESP_CHAT_VOICEEND); break;
                case MMessageID.U2C_NOTIFY_CHAT_VOICEEND: this.body = new U2C_NOTIFY_CHAT_VOICEEND(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_CHAT_VOICEEND); break;
                #endregion
                #region ROOM 3300
                case MMessageID.C2U_REQ_ROOM_PEOPLE_COUNT: this.body = new C2U_REQ_ROOM_PEOPLE_COUNT(); this.body.setMsgID((int)MMessageID.C2U_REQ_ROOM_PEOPLE_COUNT); break;
                case MMessageID.U2C_RESP_ROOM_PEOPLE_COUNT: this.body = new U2C_RESP_ROOM_PEOPLE_COUNT(); this.body.setMsgID((int)MMessageID.U2C_RESP_ROOM_PEOPLE_COUNT); break;
                case MMessageID.C2U_REQ_ENTER_ROOM: this.body = new C2U_REQ_ENTER_ROOM(); this.body.setMsgID((int)MMessageID.C2U_REQ_ENTER_ROOM); break;
                case MMessageID.U2C_RESP_ENTER_ROOM: this.body = new U2C_RESP_ENTER_ROOM(); this.body.setMsgID((int)MMessageID.U2C_RESP_ENTER_ROOM); break;
                case MMessageID.C2U_REQ_LEAVE_ROOM: this.body = new C2U_REQ_LEAVE_ROOM(); this.body.setMsgID((int)MMessageID.C2U_REQ_LEAVE_ROOM); break;
                case MMessageID.U2C_RESP_LEAVE_ROOM: this.body = new U2C_RESP_LEAVE_ROOM(); this.body.setMsgID((int)MMessageID.U2C_RESP_LEAVE_ROOM); break;
                case MMessageID.C2U_REQ_ROOM_SENDMSG: this.body = new C2U_REQ_ROOM_SENDMSG(); this.body.setMsgID((int)MMessageID.C2U_REQ_ROOM_SENDMSG); break;
                case MMessageID.U2C_RESP_ROOM_SENDMSG: this.body = new U2C_RESP_ROOM_SENDMSG(); this.body.setMsgID((int)MMessageID.U2C_RESP_ROOM_SENDMSG); break;
                case MMessageID.U2C_NOTIFY_ROOM_RECVTMSG: this.body = new U2C_NOTIFY_ROOM_RECVTMSG(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_ROOM_RECVTMSG); break;
                case MMessageID.C2U_REQ_ROOM_VOICEBEGIN: this.body = new C2U_REQ_ROOM_VOICEBEGIN(); this.body.setMsgID((int)MMessageID.C2U_REQ_ROOM_VOICEBEGIN); break;
                case MMessageID.U2C_RESP_ROOM_VOICEBEGIN: this.body = new U2C_RESP_ROOM_VOICEBEGIN(); this.body.setMsgID((int)MMessageID.U2C_RESP_ROOM_VOICEBEGIN); break;
                case MMessageID.U2C_NOTIFY_ROOM_VOICEBEGIN: this.body = new U2C_NOTIFY_ROOM_VOICEBEGIN(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_ROOM_VOICEBEGIN); break;
                case MMessageID.C2U_REQ_ROOM_SENDVOICE: this.body = new C2U_REQ_ROOM_SENDVOICE(); this.body.setMsgID((int)MMessageID.C2U_REQ_ROOM_SENDVOICE); break;
                case MMessageID.U2C_NOTIFY_ROOM_RECVVOICE: this.body = new U2C_NOTIFY_ROOM_RECVVOICE(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_ROOM_RECVVOICE); break;
                case MMessageID.C2U_REQ_ROOM_VOICEEND: this.body = new C2U_REQ_ROOM_VOICEEND(); this.body.setMsgID((int)MMessageID.C2U_REQ_ROOM_VOICEEND); break;
                case MMessageID.U2C_RESP_ROOM_VOICEEND: this.body = new U2C_RESP_ROOM_VOICEEND(); this.body.setMsgID((int)MMessageID.U2C_RESP_ROOM_VOICEEND); break;
                case MMessageID.U2C_NOTIFY_ROOM_VOICEEND: this.body = new U2C_NOTIFY_ROOM_VOICEEND(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_ROOM_VOICEEND); break;
                case MMessageID.C2U_REQ_USER_LIST: this.body = new C2U_REQ_USER_LIST(); this.body.setMsgID((int)MMessageID.C2U_REQ_USER_LIST); break;
                case MMessageID.U2C_RESP_USER_LIST: this.body = new U2C_RESP_USER_LIST(); this.body.setMsgID((int)MMessageID.U2C_RESP_USER_LIST); break;
                case MMessageID.U2C_NOTIFY_ROOM_MSGLOG_RECORD: this.body = new U2C_NOTIFY_ROOM_MSGLOG_RECORD(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_ROOM_MSGLOG_RECORD); break;
                #endregion
                #region 3400
                //case MMessageID.C2U_REQ_ROOM_BANNED: this.body = new C2U_REQ_ROOM_BANNED(); this.body.setMsgID((int)MMessageID.C2U_REQ_ROOM_BANNED); break;
                //case MMessageID.U2C_NOTIFY_ROOM_BANNED: this.body = new U2C_NOTIFY_ROOM_BANNED(); this.body.setMsgID((int)MMessageID.U2C_NOTIFY_ROOM_BANNED); break;
                //case MMessageID.U2C_RESP_ROOM_BANNED: this.body = new U2C_RESP_ROOM_BANNED(); this.body.setMsgID((int)MMessageID.U2C_RESP_ROOM_BANNED); break;
                //case MMessageID.TEST: this.body = new TEST(); this.body.setMsgID((int)MMessageID.TEST); break;
                //case MMessageID.TEST: this.body = new TEST(); this.body.setMsgID((int)MMessageID.TEST); break;
                #endregion
                default: this.body = null; break;
            }
        }
       
    }
}
